home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 455 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: lyra.csx.cam.ac.uk!nmm1
  2. From: nmm1@cus.cam.ac.uk (Nick Maclaren)
  3. Newsgroups: comp.std.c
  4. Subject: fread/fwrite [was Re: sizeof(char) ~= sizeof(float)]
  5. Date: 27 Feb 1996 19:40:07 GMT
  6. Organization: University of Cambridge, England
  7. Message-ID: <4gvmmn$6tf@lyra.csx.cam.ac.uk>
  8. References: <WALD.96Feb24131532@woodpecker.lcs.mit.edu> <4gr3d1$dca@usenet.pa.dec.com> <TANMOY.96Feb25203514@qcd.lanl.gov> <DnFr78.1wo@ukpsshp1.serigate.philips.nl>
  9. NNTP-Posting-Host: bootes.cus.cam.ac.uk
  10.  
  11. In article <DnFr78.1wo@ukpsshp1.serigate.philips.nl>,
  12. Stephen Baynes <baynes@ukpsshp1.serigate.philips.nl> wrote:
  13. >Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote:
  14. >: In article <4gr3d1$dca@usenet.pa.dec.com>
  15. >: diamond@tbj.dec.com (Norman Diamond) writes:
  16. ><snip - copying data by using chars of different sorts vs memcpy >
  17. >: This was a free-standing implementation, and memcpy may be absent. (In
  18. >: a hosted implementation, as all read/write is done as if through
  19. >: getc/putc which handles unsigned char values, and binary files written
  20. >: out must be read back unchanged, the situation is impossible).
  21. >
  22. >That read/write is done by getc/putc does not imply very much about copying
  23. >chars. I don't see any requirement that fwrite/fread use one putc/getc per
  24. >byte(ie char) of memory. Fwrite could use one per bit writing the values 'Y' or
  25. >'N' if it wanted so long as fread will read it back again. My understanding
  26. >is that the use of getc/putc means you can write a file with fwrite, copy it
  27. >with getc/putc and read the copy with fread to get what you started with.
  28.  
  29. Not quite.  You must either do ALL I/O as text or ALL as binary!  This
  30. isn't stated by the standard, but fread and fwrite are unimplementable
  31. if it is not true.  I would prefer them to be forbidden on text files,
  32. or at least implementation defined.
  33.  
  34.  
  35.  
  36. Nick Maclaren,
  37. University of Cambridge Computer Laboratory,
  38. New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
  39. Email:  nmm1@cam.ac.uk
  40. Tel.:  +44 1223 334761    Fax:  +44 1223 334679
  41.